local component = require("component")
local os = require("os")
local computer = component.computer
local io = require("io")

local function getpos(dir, co, run)
  local pos = -1
  local past = 1
  local nextbeep = 0
  while(math.abs(pos) >= 1) do
    local posa = {component.navigation.getPosition()}
    pos = posa[co]
    if past >= nextbeep then
      print("Move " .. dir .. " " .. pos)
      if math.abs(pos) >= 1 then
        computer.beep(math.max(500 - (math.abs(pos) * 10), 100) * run)
      end
      past = 0
    end
    os.sleep(0.1)
    past = past + 0.5
    nextbeep = math.min((math.abs(pos) / 20), 4)
  end
end

getpos("X", 1, 1)
computer.beep(200, 0.05)
computer.beep(300, 0.05)
computer.beep(200, 0.05)
getpos("Z", 3, 2)
computer.beep(500, 0.05)
computer.beep(400, 0.05)
computer.beep(700, 0.09)
computer.beep(800, 0.09)

print("You have reached 0,0 of the map")
print("Please enter the X position")
local startx = io.read()
print("Please enter the Z position")
local startz = io.read()

local f = io.open("/.gps_start.pos", "w")
f:write(startx, "\n", startz)
f:close()
print("GPS position stored")
